package vn.gq.udv.comic.model.item;

import org.json.JSONException;
import org.json.JSONObject;
import android.os.Parcel;
import android.os.Parcelable;

public class ChapterItem implements Parcelable {
	
	private String chapterId;
	private String title;
	
	public ChapterItem() {
	}
	
	public ChapterItem(String _id, String _title) {
		chapterId = _id;
		title = _title;
	}
	
	public ChapterItem(JSONObject in) {
		try {
			title = in.getString("title");
			chapterId = in.getString("chapterId");
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
	
	public ChapterItem(String json) {
		try {
			JSONObject ob = new JSONObject(json);
			title = ob.getString("title");
			chapterId = ob.getString("chapterId");
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
	
	public ChapterItem(Parcel source) {
		chapterId = source.readString();
		title = source.readString();
	}
	
	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(chapterId);
		dest.writeString(title);
	}
	
	public JSONObject toJsonObject() {
		JSONObject out = new JSONObject();
		try {
			out.put("chapterId", chapterId);
			out.put("title", title);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return out;
	}
	
	public static final Parcelable.Creator<ChapterItem> CREATOR = new Creator<ChapterItem>() {
		
		@Override
		public ChapterItem[] newArray(int size) {
			return new ChapterItem[size];
		}
		
		@Override
		public ChapterItem createFromParcel(Parcel source) {
			return new ChapterItem(source);
		}
	};
	
	public String getChapterId() {
		return chapterId;
	}
	
	public void setChapterId(String chapterId) {
		this.chapterId = chapterId;
	}
	
	public String getTitle() {
		return title;
	}
	
	public void setTitle(String title) {
		this.title = title;
	}
	
}
